package problems;

import lib.MathLib;

public class Euler050 extends AbstractEuler {

	@Override
	public Number calculate() {
		int maxConsecutivePrimes = 21;
		int maxConsecutivePrimesSum = 953;

		for (int start = 1; start < 5; start++) {
			for (int i = start, consecutivePrimes = 1, consecutivePrimesSum = 0; consecutivePrimesSum < 1000000; i++, consecutivePrimes++) {
				consecutivePrimesSum += MathLib.getPrime(i);
				if (consecutivePrimes > maxConsecutivePrimes) {
					if (MathLib.isPrime(consecutivePrimesSum)) {
						maxConsecutivePrimes = consecutivePrimes;
						maxConsecutivePrimesSum = consecutivePrimesSum;
					}
				}
			}
			
		}
		
		return maxConsecutivePrimesSum;
		
	}

	@Override
	protected Number getCorrectAnswer() {
		return 997651;
	}

}
